# soup = '这是一碗汤'
# soup_2 = "这也是一碗汤"
#
# print(soup, soup_2)


# # 长字符串
# long_text = 'aaa这也是一碗汤这也是一碗汤这也是一碗汤这也是一碗汤这也是一碗汤这也是一碗汤' \
#             'bbb这也是一碗汤这也是一碗汤这也是一碗汤这也是一碗汤这也是一碗汤这也是一碗汤这' \
#             'ccc也是一碗汤这也是一碗汤这也是一碗汤这也是一碗汤'
#
# print(long_text)

# text = """第一行
# 第二行
# 第三行
# """
# print(text)
#
# # 求字符串的长度 length的缩写
# print(len(text))

# 连接 和 乘法
# name = '王鑫' + '你好'  # 加法 理解成连接 concat
# print(name)

# name = '王鑫' * 3  # 乘法 理解成重复3次的意思
# print(name)

# 按索引取 子字符串
# text = '987654321'
# text = '王鑫撒旦法撒旦发'
#
# # print(text[0])
# # print(text[5])
# print(text[-1])
# print(text[-2])
# print(text[-0])
# print(text[100])

# # 切片
# text = '王鑫撒旦法撒旦发'
# sub_text = text[1:4]
# print(sub_text)
#
# sub_text2 = text[1:]
# print(sub_text2)
#
# sub_text2 = text[:-2]
# print(sub_text2)
# text = 'abcdefg'
# sub_text2 = text[::3]  # [起始位置:终止位置:步长]
# print(sub_text2)


# 字符串的函数
#
# a = 'xYz'
# print(len(a))
#
# b = a.upper()  # 全大写
# print(b)
# print(a)
# print(a.lower()) # 全小写

# index  求索引
# text = 'The black cat climbed the green tree.'
# print(text.index('bl'))
# print(text.index('The'))
# print(text.index('the'))
# # print(text.index('dog'))  # 报错
#
# print(text.index('c'))
# print(text.index('c', 8))
#
# print(text.index('gr', 8))
# print(text[26:])
# print(text[8:16])
# print(text.index('gr', 8, 16))

# # 从右往左找
# text = 'The black cat climbed the green tree.'
# print(text.rindex('c'))
# print(text[:14])
# print(text[14:])

# find
# text = 'The black cat climbed the green tree.'
#
# print(text.find('王鑫'))
# # print(text.index('王鑫'))
# print(text.find('The'))
# print(text.find('the'))
# # print(text.find('dog'))  # 报错
#
# print(text.rfind('c'))  # 可以从右往左找
# print(text.find('c', 8))

# 单独的 【in 字符串】 判断是否存在的意思

text = 'hello world'
# print('wo' in text)  # 判断的意思
# if 'wo' in text:
#     print('找了 wo 子字符串')
#
# # 循环里是迭代的意思
# for i in text:
#     print(i)

# if 'x' in text:
#     print('yes')
# else:
#     print('No')



# print(dir(text))  # 可以用来提示有什么方法
# print(dir([]))  # 可以用来提示有什么方法


# 特殊字符串
# \n 换行
# \t 一个制表符
# \a
# print('你好\n123')
# print('你好\'123')
# print("你好\"123")

# print(ord('a'))  # 转成unicode
# print(ord('鑫'))  # 转成unicode
# print(chr(97))  # 转成unicode
# print(chr(98))  # 转成unicode

# for i in range(1, 150):
#     print(chr(i))

# format - sprintf 基本的
#
# age = 42.12
# name = '王鑫'
#
# str_concatenate = "The user " + name + " was born " + str(age) + " years ago."
# print(str_concatenate)
#
# # 占位的意思
# str_percentage = "The user %s was born %s years ago." % (name, age)
# print(str_percentage)
#
# str_format = "The user {} was born {} years ago.".format(name, age)
# print(str_format)
#
# str_f_string = f"The user {name} was born {age} years ago."
# print(str_f_string)

# Examples using format - indexing
# # 使用索引
#
# txt = "王鑫"
# num = 42.12
# ss = 'asfas'
#
# print("The user {} was born {} years ago.".format(txt, num))
# print("The user {0} was born {1} years ago.".format(txt, num, ss))
# print("The user {1} was born {0} years ago.".format(num, txt))
#
#
# print("{0} is {0} and {1} years old.".format(txt, num))


# Examples using format with names
# 使用带有名称的格式的示例
# txt = "王鑫"
# num = 42.12
#
# print("The user {name} was born {age} years ago.".format(name=txt, age=num))

# Format columns

# data = [
#     ["Foo Bar", 42],
#     ["Bjorg", 12345],
#     ["Roza", 7],
#     ["Long Name Joe", 3],
#     ["Joe", 12345677889],
# ]
#
# for entry in data:
#     print("{} {}".format(entry[0], entry[1]))
#
# print('-' * 16)
#
# for entry in data:
#     print("{:<8}|{:>7}".format(entry[0], entry[1]))

# Examples using format - alignment
# 使用格式对齐方式的示例

# txt = "Some text"
#
# print("'{}'".format(txt))  # as is: 'Some text'
# print("'{:12}'".format(txt))  # left: 'Some text '
# print("'{:<12}'".format(txt))  # left: 'Some text '
# print("'{:>12}'".format(txt))  # right: ' Some text'
# print("'{:^12}'".format(txt))  # center: ' Some text '

# Format - string
#
# name = "Foo Bar"
#
# print("{:s}".format(name))
# print("{}".format(name))
#
# Format characters and types
# 格式化字符和类型

# x = 42
#
# print("{:b}".format(x))  # binary: 101010
# print("{:c}".format(x))  # character: *  ascii
# print(chr(x))  # character: *  ascii
# print("{:c}".format(97))  # character: *
#
# print("{:d}".format(x))  # decimal: 42 (default)
# print("{:o}".format(x))  # octal: 52
# print("{:x}".format(x))  # hexa: 2a
# print("{:X}".format(x))  # hexa: 2A
# print("{:n}".format(x))  # number: 42
#
# print("{}".format(x))  # defaults to decimal

# Format floating point number
# 格式化浮点数
#
# x = 412.345678901
#
# print("{:e}".format(x))  # exponent: 4.123457e+02
# print("{:E}".format(x))  # Exponent: 4.123457E+02
# print("{:f}".format(x))  # fixed point: 412.345679 (default precision is 6)
# print("{:0.13f}".format(x))  # fixed point: 412.345679 (default precision is 6)
# print("{:.2f}".format(x))  # fixed point: 412.35 (set precision to 2)
# print("{:.3f}".format(x))  # fixed point: 412.35 (set precision to 2)
# print("{:F}".format(x))  # same as f. 412.345679
# print("{:g}".format(x))  # generic: 412.346 (default precision is 6)
# print("{:G}".format(x))  # generic: 412.346
# print("{:n}".format(x))  # number: 412.346
#
# print("{}".format(x))  # defaults to g 412.345678901

# f-strings (formatted string literals)
# name = "Foo Bar"
# age = 42.12
# pi = 3.141592653589793
# r = 2
#
# print(f"The user {name} was born {age} years ago.")
# print(f"The user '{name:10}' was born {age} years ago.")
# print(f"The user '{name:>10}' was born {age} years ago.")
# print(f"The user '{name:>10}' was born {age:>10} years ago.")
#
# print(f"PI is '{pi:.3}'.")  # number of digits (defaults n = number)
# print(f"PI is '{pi:.3f}'.")  # number of digits after decimal point
#
# print(f"Area is {pi * r ** 2}")
# print(f"Area is {pi * r ** 2:.3f}")

# printf using old %-syntax
# v = 65
# print("<%s>" % v)  # <65>
# print("<%10s>" % v)  # < 65>
# print("<%-10s>" % v)  # <65 >
# print("<%c>" % v)  # <A>  chr(65)
# print("<%d>" % v)  # <65> d十进制的意思
# print("<%0.6d>" % v)  # <00065>


# Format braces, bracket, and parentheses
# 格式化大括号、大括号和圆括号

# print("{{{}}}".format(42))  # {42}
#
# print("{{ {} }}".format(42))  # { 42 }
#
# print("[{}] ({})".format(42, 42))  # [42] (42)
#
# print("%{}".format(42))  # %42


# raw f-strings
# 生f-strings，不转义
#
# name = "foo"
# print(r"a\nb {name}")
# print(rf"a\nb {name}")
# print(fr"a\nb {name}")  # this is better (for vim)
